package com.pc.web.boardEvent;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

@Service
public class BoardEventService {
	@Autowired BoardEventDAO dao;

	public void listpage(BoardEventBeans beans, PageEventBeans Pbeans, Model model){

		int page=1;
		int limit=10;
		int pageGroupSize=10;

		if(Pbeans.getPage()!=0){
			page=(Pbeans.getPage());
		}
		if(Pbeans.getLimit()!=0){
			limit=(Pbeans.getLimit());
		}
		int currentPage = page;

		int startrow = (currentPage - 1) * pageGroupSize + 1;//한 페이지의 시작글 번호
        int endrow = currentPage * pageGroupSize;//한 페이지의 마지막 글번호
		beans.setStartrow(startrow);
		beans.setEndrow(endrow);

		int listcount=dao.getListCount();

		int count1=listcount / pageGroupSize + (listcount % pageGroupSize == 0 ? 0 : 1);
		int count2=currentPage / 10;

		// ----- 검색
		String searchType=beans.getSearchType();
		String keyword=beans.getKeyword();
		
		beans.setSearchType(searchType);
		beans.setKeyword(keyword);
		// -----

		Pbeans.setPage(currentPage);
		Pbeans.setLimit(limit);
		Pbeans.setListcount(listcount);
		Pbeans.setPagegroupsize(pageGroupSize);		
		List<BoardEventBeans> boardEventList =null;

		boardEventList=dao.getBoardEventList(beans);

		model.addAttribute("list", boardEventList);
		model.addAttribute("Pbeans", Pbeans);
		model.addAttribute("count1", count1);
		model.addAttribute("count2", count2);
	}

	public void view(String boardEvent_no, BoardEventBeans beans, Model model){
		beans=dao.detailView(boardEvent_no);
		List cList=dao.commentList(boardEvent_no);
		System.out.println("service = " + boardEvent_no);
		model.addAttribute("beans", beans);
		model.addAttribute("cList", cList);
	}
}